package Boundary;

import Control.Service.impl.StudentServiceImpl;
import Entity.ModulesGrades;
import Entity.RolesUndertaken;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import static Control.Control.*;

/**
 * @author Group77
 * @version 4.0
 * @description display an operational page for deleting roles
 */
public class RoleDelete extends Overall{
    /**
     * initialize the Jframe
     *
     * @param number : the name of each frame
     */
    public RoleDelete(int number) {
        super("Delete");

        StudentServiceImpl ss = new StudentServiceImpl();

        panel1.setLayout(new BorderLayout());
        panel1.setBorder(BorderFactory.createEmptyBorder());
        JButton button0 = new JButton("   Go back   ");
        button0.setBorder(BorderFactory.createRaisedBevelBorder());
        button0.setBackground(Color.cyan);
        button0.setFont(new Font("STSong", Font.BOLD, 25));
        JPanel empty1 = new JPanel();
        empty1.setPreferredSize(new Dimension(100, 10));
        panel1.add(button0, BorderLayout.WEST);
        panel1.add(empty1, BorderLayout.NORTH);
        Add_Component(jfr, gbl, panel1, gbc, 0, 0, 1, 1, 1, 0);


        button0.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);
                        new RolesManagement(number);
                        jfr.dispose();
                    }
                }
        );

        JLabel label2 = new JLabel("Role Name   :", JLabel.CENTER);
        label2.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        JTextField tf2 = new JTextField(12);
        tf2.setFont(new Font("TimesRoman", Font.PLAIN, 24));
        Box b2 = Box.createHorizontalBox();
        b2.add(label2);
        b2.add(Box.createHorizontalStrut(10));
        b2.add(tf2);
        panel3.add(b2);
        Add_Component(jfr, gbl, panel3, gbc, 0, 1, 1, 1, 1, 0);

        panel7.setBorder(BorderFactory.createEmptyBorder());
        JButton button2 = new JButton("   Confirm   ");
        button2.setBorder(BorderFactory.createRaisedBevelBorder());
        button2.setBackground(Color.LIGHT_GRAY);
        button2.setFont(new Font("TimesRoman", Font.BOLD, 30));
        JPanel emp = new JPanel();
        emp.setPreferredSize(new Dimension(700, 10));
        emp.setBorder(BorderFactory.createEmptyBorder());
        panel7.add(emp);
        panel7.add(button2, BorderLayout.CENTER);
        Add_Component(jfr, gbl, panel7, gbc, 0, 7, 1, 1, 1, 1);

        button2.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        jfr.setVisible(false);
                        List<RolesUndertaken> RU=json3.readArray(RolesUndertaken.class);
                        int j=ss.Role_check(number,tf2.getText());
                        RU.remove(j);
                        json3.writeArray(RU);
                        new RolesManagement(number);
                        jfr.dispose();
                    }
                }
        );


    }
}
